package org.arain.baseii.system.role;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.arain.baseii.grid.AMGrid;
import org.arain.baseii.grid.ColumnsPojo;
import org.arain.baseii.grid.QueryParam;
import org.arain.baseii.utils.ArainResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 
* <p>Title:SysRoleController </p>
* @author Arain
* @date2017年8月31日
 */
@Controller
@RequestMapping("system/role")
public class SysRoleController {
	@Autowired
	private SysRoleService sysRoleService;
	
	
	@RequestMapping("list_01")
	public String list_01(Model model,HttpServletRequest request) {
		List<ColumnsPojo> columns = new ArrayList<>();
		AMGrid grid = new AMGrid("id");
		grid.setUrl("/system/role/load_grid.do");
		grid.setToolbar("RoleToolbar");
		ColumnsPojo pojo;
		pojo = new ColumnsPojo("name", "名称");
		columns.add(pojo);
		pojo = new ColumnsPojo("sort", "排序");
		columns.add(pojo);
		pojo = new ColumnsPojo("operator", "经办人");
		columns.add(pojo);
		pojo = new ColumnsPojo("optime", "经办时间");
		columns.add(pojo);
		pojo = new ColumnsPojo("enabled", "是否可用");
		columns.add(pojo);
		grid.setColumns(columns.toString());
		
		model.addAttribute("dataGrid", grid.toString());
		return "system/role/list_01";
	}
	
	@RequestMapping(value="load_grid.do",produces="text/json;charset=UTF-8")
	@ResponseBody
	public String load_grid(QueryParam param) {
		return sysRoleService.load_grid(param);
	}
	
	@RequestMapping("add_01")
	public String add_01(SysRoleDto dto,HttpServletRequest request,Model model) {
		dto.setEnabled("1");
		model.addAttribute("sysRoleDto", dto);
		return "system/role/add_01";
	}
	
	@RequestMapping(value="load_resource.do",produces="text/json;charset=UTF-8")
	@ResponseBody
	public String load_resource(SysRoleDto dto) {
		return sysRoleService.load_role_resource(dto);
	}
	
	@RequestMapping(value="load_resource_edit.do",produces="text/json;charset=UTF-8")
	@ResponseBody
	public String load_resource_edit(SysRoleDto dto) {
		return sysRoleService.load_role_resource(dto);
	}
	
	@RequestMapping("save.do")
	@ResponseBody
	public ArainResult save_01(SysRoleDto dto) {
		return sysRoleService.save_01(dto);
	}

	@RequestMapping("edit_01")
	public String edit_01(SysRoleDto dto,HttpServletRequest request,Model model) {
		dto = sysRoleService.load_01(dto);
		model.addAttribute("sysRoleDto", dto);
		return "system/role/add_01";
	}
}
